package com.codinghero.example.longleg;

import java.io.File;
import java.sql.SQLException;

import com.codinghero.sql.DBOper;
import com.codinghero.sql.MySQLOper;

public class GenerateOldGirlPicSql {
	
	private final static String LOOD_UP_BASE_FOLDER = "F:\\girleg\\qiniu";
	private static String[] LOOK_UP_FOLDERS = {
		"\\file\\2013\\0601\\",
		"\\file\\2013\\0602\\",
		"\\file\\2013\\0603\\",
		"\\file\\2013\\0604\\"
	};
	
	public static void main(String[] args) throws SQLException {
		File folder = new File("F:\\girleg\\orig_backup\\王李丹妮");
		File[] files = folder.listFiles();
		
		DBOper db = new MySQLOper("jdbc:mysql://localhost:3306/girleg?useUnicode=true&characterEncoding=utf8","root","sa");
		db.connect();
		System.out.println("INSERT INTO girl_pic(girl_id, pic_id) VALUES");
		for (File file : files) {
			for (String lookUpFolder : LOOK_UP_FOLDERS) {
				String lookUpFilePath = LOOD_UP_BASE_FOLDER + lookUpFolder + file.getName();
				if (new File(lookUpFilePath).exists()) {
					Pic pic = db.selectOne("select * from pic where relative_path='"
							+ (lookUpFolder + file.getName()).replace(File.separator, "/") + "'", Pic.class);
					if (pic != null && pic.getId() != null)
						System.out.println("(" + Constant.GIRL.ID + "," + pic.getId() + "),");
					break;
				}
			}
		}
		db.close();
	}
}
